package com.cjm.one.webmanager.controller.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.goods.entity.GoodsCategory;
import com.cjm.one.model.goods.vo.GoodsCategoryVo;
import com.cjm.one.webmanager.service.goods.GoodsCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manager/goods/category")
@Slf4j
@Tag(name = "2-商品分类管理", description = "商品分类管理")
public class GoodsCategoryController {
    @Resource
    private GoodsCategoryService goodsCategoryService;
    @GetMapping("/list")
    @Operation(summary = "商品分类列表")
    public Result<List<GoodsCategoryVo>> getPage(@RequestParam(name = "searchKey",required = false) String searchKey) {
        return Result.ok(goodsCategoryService.list( searchKey));
    }
    @GetMapping("/ToParentId")
    @Operation(summary = "商品分类树")
    public Result<List<GoodsCategory>> getToParentId(@RequestParam(name = "parentId",required = true) Long parentId){
        return Result.ok(goodsCategoryService.listByParentId(parentId));
    }
    @GetMapping("/{id}")
    @Operation(summary = "商品分类详情")
    Result<GoodsCategoryVo> getById(@PathVariable("id") Long id){
        return Result.ok(goodsCategoryService.getByIdVo(id));
    }
    @PutMapping
    @Operation(summary = "商品分类修改")
    public Result<Boolean> update(@RequestBody GoodsCategory goodsCategory) {
        return Result.ok(goodsCategoryService.updateById(goodsCategory));
    }
    @PostMapping
    @Operation(summary = "商品分类添加")
    public Result<Boolean> save(@RequestBody GoodsCategory goodsCategory) {
        return Result.ok(goodsCategoryService.save(goodsCategory));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "商品分类删除")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.ok(goodsCategoryService.removeById(id));
    }

}
